import { computed } from 'vue'
import { useMessage } from 'naive-ui'
import { t } from '@/locales'
import { useChatStore } from '@/store'
import {clearContext} from "@/api";

export function useUsingContext() {
  const ms = useMessage()
  const chatStore = useChatStore()
  const usingContext = computed<boolean>(() => chatStore.usingContext)

	async function toggleUsingContext() {

		const param = {
			username: localStorage.getItem('username')
		}
		const result = confirm("确定要清空上下文吗，清空之后ChatGPT将忘记您之说的话~")
		if (result){
			const {state} = await clearContext(param)
			console.log(state)
			if (state.code === '0'){
				ms.success(t('chat.turnOnContext'))
			}else {
				ms.warning(t('chat.turnOnContextFail'))
			}
		}
	}

  return {
    usingContext,
    toggleUsingContext,
  }
}
